import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';
import { NamespaceCodeEnum } from '/@/enums/iamEnum'
import { getBizUrl } from '/@/utils/common/bizUrlUtils'
export const deleteMenuBindPermPolicy = (params) => {
  let url = '/system-service/authorize/deleteMenuBindPermPolicy'
  return defHttp.delete({url: url, params});
}

export const listSubjectMenuTree = (params) => {
  return defHttp.get({url: '/iam-service/authorize/listUserMenuTree', params});
}

export const listSubjectPermPolicy = (params) => {
  return defHttp.get({url: getBizUrl(params, '/iam-service/authorize/listSubjectPermPolicy'), params});
}

export const listUserPermPolicy = (params) => {
  return defHttp.get({url: '/iam-service/authorize/listUserPermPolicy', params});
}

export const assignPermPolicyToRole = (params) => {
  let url = getBizUrl(params, '/iam-service/authorize/assignPermPolicyToRole')
  return defHttp.post({url: url, params});
}

export const assignPermPolicyToOauthClient = (params) => {
  let url = '/iam-service/authorize/assignPermPolicyToOauthClient'
  return defHttp.post({url: url, params});
}

export const assignPermPolicyToUser = (params) => {
  let url = '/iam-service/authorize/assignPermPolicyToUser'
  return defHttp.post({url: url, params});
}

export const deleteUserPermPolicy = (params, handleSuccess) => {
  return defHttp.delete({url: '/iam-service/authorize/deleteUserPermPolicy', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const deleteRolePermPolicy = (params, handleSuccess) => {
  return defHttp.delete({url: '/iam-service/authorize/deleteRolePermPolicy', data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const listMenuResourceByUrl = (params) => {
  return defHttp.get({url: '/system-service/resource/listMenuResourceByUrl', params });
}


export const getPermissionPolicy = (params) => {
  return defHttp.get({url : getBizUrl(params, '/iam-service/%s/permissionPolicy/get') , params});
}

export const pagePermissionPolicy = (params) => {
  return defHttp.get({url: getBizUrl(params, '/iam-service/%s/permissionPolicy/page') , params});
}

export const savePermissionPolicy = (params) => {
  let url : any = getBizUrl(params, '/iam-service/%s/permissionPolicy/save')
  return defHttp.post({url: url, params});
}

export const updateMenuPermissionPolicy = (params) => {
  let url : any = getBizUrl(params, '/iam-service/%s/permissionPolicy/updateMenu')
  return defHttp.post({url: url, params});
}

export const updateApiPermissionPolicy = (params) => {
  let url : any = getBizUrl(params, '/iam-service/%s/permissionPolicy/updateApi')
  return defHttp.post({url: url, params});
}

export const deletePermissionPolicy = (params, handleSuccess) => {
  let url : any = getBizUrl(params, '/iam-service/%s/permissionPolicy/delete')
  return defHttp.delete({url: url, data: params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

export const batchDeletePermissionPolicy = ( params, handleSuccess) => {
  let url : any = getBizUrl(params, '/iam-service/%s/permissionPolicy/batchDelete')
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess(); 
     });
    }
  });
}
